mtd: spi-nor: fix page program issue when using spi-mem driver
authorWeijie Gao <[email protected]>
Fri, 26 Apr 2019 09:22:19 +0000 (17:22 +0800)
committerJagan Teki <[email protected]>
Fri, 3 May 2019 09:56:12 +0000 (15:26 +0530)
commit60e2bf46784ebbd30ff29b3d3c7c97e56b11e86a
tree0470e4ed60e08dffd1eb3508e4461de2f0758cdc
parentb4ee6daad7a2604ca9466b2ba48de86cc27d381f
mtd: spi-nor: fix page program issue when using spi-mem driver

Some SPI controllers can't write nor->page_size bytes in a single step
because their TX FIFO is too small, but when that happens we should
make sure a WRITE_EN command before each write access and READ_SR command
after each write access is issued.

We should allow nor->write() to return a size that is smaller than the
requested write size to gracefully handle this case.

Also, the spi_nor_write_data() should return the actual number of bytes
that were written during the spi_mem_exec_op() operation.

This patch is a combination of two commits backported from kernel:

  commit 630d6bd8a3b4 ("mtd: spi-nor: Support controllers with limit ...")
  commit 3baa8ec88c2f ("mtd: devices: m25p80: Make sure WRITE_EN is ...")

Cc: Vignesh R <[email protected]>
Signed-off-by: Weijie Gao <[email protected]>
Acked-by: Vignesh R <[email protected]>
Tested-by: Shyam Saini <[email protected]> # microzed
Acked-by: Jagan Teki <[email protected]>
drivers/mtd/spi/spi-nor-core.c